//
//  DAPersonalBookHistoryTableViewCell.m
//  DAKnowledge
//
//  Created by DreamArts on 16/5/3.
//  Copyright © 2016年 lidongyang. All rights reserved.
//

#import "DAPersonalBookHistoryTableViewCell.h"
#import "DALabel.h"
#import "DAHeader.h"
#import "Utility.h"
#import "DAImageView.h"
#import "DAHomePageTimeLineModel.h"
#import "UIImageView+WebCache.h"

@interface DAPersonalBookHistoryTableViewCell ()
@property (weak, nonatomic) IBOutlet UILabel *lineLabel;
@property (weak, nonatomic) IBOutlet UIImageView *statusImageView;
@property (weak, nonatomic) IBOutlet DALabel *timeAndStatusLabel;
@property (weak, nonatomic) IBOutlet UIImageView *bookImage;
@property (weak, nonatomic) IBOutlet DALabel *lenderLabel;
@property (weak, nonatomic) IBOutlet DALabel *borrowTimeLabel;
@property (weak, nonatomic) IBOutlet DALabel *bookNameLabel;
@property (weak, nonatomic) IBOutlet UIView *statusView;

@end
@implementation DAPersonalBookHistoryTableViewCell

- (void)awakeFromNib {
    // Initialization code
}
- (void)setStatusImageView:(UIImageView *)statusImageView{
   // statusImageView.layer.cornerRadius = 10;
   // statusImageView.clipsToBounds = YES;
    //statusImageView.backgroundColor = [UIColor whiteColor];
    statusImageView.image = [UIImage imageNamed:@"book@3x"];
}
//- (void)setTimeAndStatusLabel:(UILabel *)timeAndStatusLabel{
//    timeAndStatusLabel.text = @"47分钟前  归还了";
//    timeAndStatusLabel.textColor = [UIColor colorWithHexString:timeColor];
//    timeAndStatusLabel.font = [UIFont systemFontOfSize:12];
//}
//- (void)setLineLabel:(UILabel *)lineLabel{
//    lineLabel.backgroundColor = [UIColor colorWithHexString:timeLineColor];
//}
//- (void)setBookImage:(UIImageView *)bookImage{
//    bookImage.image = [UIImage imageNamed:@"Java.jpg"];
//    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(showBookDetail:)];
//    bookImage.userInteractionEnabled = YES;
//    [bookImage addGestureRecognizer:tap];
//    [bookImage.layer setBorderColor:[UIColor whiteColor].CGColor];
//    [bookImage.layer setBorderWidth:3];
//}
//- (void)setBookNameLabel:(DALabel *)bookNameLabel{
//    bookNameLabel.textColor = [UIColor colorWithHexString:bookNameColor];
//    [bookNameLabel setText:@"谭浩强C语言程序设计" fitToContent:YES];
//    bookNameLabel.font = [UIFont systemFontOfSize:13];
//    bookNameLabel.verticalAlignment = VerticalAlignmentTop;
//}
//- (void)setLenderLabel:(DALabel *)lenderLabel{
//    lenderLabel.textColor = [UIColor colorWithHexString:lenderColor];
//    [lenderLabel setText:@"出借人:图书室" fitToContent:YES];
//    lenderLabel.font = [UIFont systemFontOfSize:11];
//}
//- (void)setBorrowTimeLabel:(DALabel *)borrowTimeLabel{
//    borrowTimeLabel.textColor = [UIColor colorWithHexString:borrowTimeColor];
//    [borrowTimeLabel setText:@"借阅期:三个月" fitToContent:YES];
//    borrowTimeLabel.font = [UIFont systemFontOfSize:11];
//}
//- (void)setStatusView:(UIView *)statusView{
//    statusView.layer.cornerRadius = 10;
//    statusView.backgroundColor = [UIColor colorWithHexString:@"#BFBFBF"];
//}

- (void)setTimeLineModel:(DAHomePageTimeLineModel *)timeLineModel{
    if (_timeLineModel != timeLineModel) {
        _timeLineModel = timeLineModel;
    }
   // NSString *str;
    self.statusView.layer.cornerRadius = 10;
    self.statusView.backgroundColor = [UIColor supportGreenColor];
//    if ([timeLineModel.timelineType isEqualToString:@"1"]) {
//        self.statusView.backgroundColor = [UIColor supportGreenColor];
//        str = [NSString stringWithFormat:@"%@ 借阅了", timeLineModel.timelineDate];
//        
//    }else{
//        self.statusView.backgroundColor = [UIColor colorWithHexString:@"#BFBFBF"];
//        str = [NSString stringWithFormat:@"%@ 归还了", timeLineModel.timelineDate];
//    }
    
    NSString *str = [NSString stringWithFormat:@"%@ %@", timeLineModel.timelineDate, NSLocalizedString(@"Borrow", nil)];
    
    // 时间和类型
    [self.timeAndStatusLabel setText:str fitToContent:YES];
    self.timeAndStatusLabel.textColor = [UIColor colorWithHexString:timeColor];
    self.timeAndStatusLabel.font = [UIFont systemFontOfSize:12];
    // 时间轴
    self.lineLabel.backgroundColor = [UIColor colorWithHexString:timeLineColor];
    // 图书 图片
    
    UIView *bookCover = [[UIView alloc]initWithFrame:CGRectMake(0 , 0, self.bookImage.frame.size.width, self.bookImage.frame.size.height)];
    bookCover.backgroundColor = [UIColor supportGreenColor];
    DALabel *bookCoverName = [[DALabel alloc]initWithFrame:CGRectMake(5, 5, bookCover.frame.size.width -10, bookCover.frame.size.height - 10)];
    bookCoverName.verticalAlignment = VerticalAlignmentMiddle;
    bookCoverName.textAlignment = NSTextAlignmentCenter;
    [bookCoverName setText:timeLineModel.bookName fitToContent:YES];
    [bookCoverName setTextColor:[UIColor whiteColor]];
    bookCoverName.font = [UIFont systemFontOfSize:12];
    [bookCover addSubview:bookCoverName];
    
    UIImage *image = [self makeImageWithView:bookCover];
    
    [self.bookImage sd_setImageWithURL:[NSURL URLWithString:timeLineModel.bookImage] placeholderImage:image];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(showBookDetail:)];
    self.bookImage.userInteractionEnabled = YES;
    [self.bookImage addGestureRecognizer:tap];
    [self.bookImage.layer setBorderColor:[UIColor whiteColor].CGColor];
    [self.bookImage.layer setBorderWidth:3];
    // 图书名
    self.bookNameLabel.textColor = [UIColor colorWithHexString:bookNameColor];
    [self.bookNameLabel setText:timeLineModel.bookName fitToContent:YES];
    self.bookNameLabel.font = [UIFont systemFontOfSize:13];
    self.bookNameLabel.verticalAlignment = VerticalAlignmentTop;
    // 出借人
    NSString *bookSource = NSLocalizedString(@"bookSource", nil);
    NSString *lenderStr = [NSString stringWithFormat:@"%@: %@", bookSource,timeLineModel.bookSource];
    self.lenderLabel.textColor = [UIColor colorWithHexString:lenderColor];
    [self.lenderLabel setText:lenderStr fitToContent:YES];
    self.lenderLabel.font = [UIFont systemFontOfSize:12];
    // 借阅期
    NSString *bookBorrowTime = NSLocalizedString(@"borrowTime", nil);
    NSString *borrowTimeStr = [NSString stringWithFormat:@"%@: %@", bookBorrowTime,timeLineModel.borrowDuration];
    self.borrowTimeLabel.textColor = [UIColor colorWithHexString:borrowTimeColor];
    [self.borrowTimeLabel setText:borrowTimeStr fitToContent:YES];
    self.borrowTimeLabel.font = [UIFont systemFontOfSize:12];
    
}



#pragma mark - 手势方法
- (void)showBookDetail:(UITapGestureRecognizer *)tap{
    [self.delegate clickBookImage:self.timeLineModel.bookID];
}





- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
